﻿namespace Acme.Marketing.DataAccess
{
    using System;
    using System.Linq;

    /// <summary>
    ///     This interface represents a basic Repository pattern for data access using Entity Framework or another replaceable
    ///     ORM.
    /// </summary>
    /// <typeparam name="T">The type of object being used.</typeparam>
    public interface IMarketingRepository<T> : IDisposable where T : class
    {
        /// <summary>
        ///     Gets the T based on the identifier.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>A singular entity of type T.</returns>
        T Get(int id);

        /// <summary>
        ///     Attaches the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Attach(T entity);

        /// <summary>
        ///     Gets all of the records.
        /// </summary>
        /// <returns>An IQueryable result set of the records of type T.</returns>
        IQueryable<T> GetAll();

        /// <summary>
        ///     Inserts the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Insert(T entity);

        /// <summary>
        ///     Deletes the specified entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        void Delete(T entity);

        /// <summary>
        ///     Submits the changes to the database, completing the transaction.
        /// </summary>
        void SaveChanges();
    }
}